package com.abel.bigwater.dataserver.model.hgd

import io.netty.buffer.ByteBuf

/**
 * 06 0E 00126789 00126489 00326780
 * 类型 通道号 M 数据 1 M 数据 2 M 数据 3
 * M14
 */
class MChannel(count: Short) : HgdChannel<Int>(HgdChannelType.M_TYPE, count) {
    /**
     * compute length of bytes.
     */
    override fun bufLength() = 2 + 4 * count

    /* (non-Javadoc)
     * @see com.abel.bigwater.dataserver.model.hgd.HgdChannel#parseBuffer(io.netty.buffer.ByteBuf)
     */
    override fun parseBuffer(buf: ByteBuf): Boolean {
        super.parseBuffer(buf)

        for (i in 1..count) {
            values.add(buf.readInt())
        }

        return true
    }

    /* (non-Javadoc)
     * @see com.abel.bigwater.dataserver.model.hgd.HgdChannel#pack(io.netty.buffer.ByteBuf)
     */
    override fun pack(buf: ByteBuf): Boolean {
        super.pack(buf)

        for (i in 1..count) {
            buf.writeInt(values[i])
        }

        return true
    }

}
